package mysql

import (
	"gorm.io/gorm"
	"user-auth/userrpc/userrpc"
)

type Goods struct {
	gorm.Model
	GoodsName  string  `gorm:"type:varchar(30);not null;comment:'商品名称'"`
	GoodsPrice float32 `gorm:"type:decimal(10,2);not null;comment:'商品价格'"`
	GoodsStock int64   `gorm:"type:int(11);not null;comment:'商品数量'"`
	UserId     int64   `gorm:"type:int(11);not null;comment:'用户id'"`
}

func (g *Goods) GoodsAdd(db *gorm.DB) error {
	return db.Debug().Create(g).Error
}

func GoodsList(db *gorm.DB, list []*userrpc.GoodsList) ([]*userrpc.GoodsList, error) {
	err2 := db.Debug().Model(&Goods{}).Select("goods.*,users.mobile").
		Joins("left join users on users.id=goods.user_id").
		Find(&list).Error
	return list, err2
}
